package com.uvlab.sitespot.init;

/**
 * Created by allen on 6/11/2016.
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Spring Boot 静态资源处理, 2016,
 * http://blog.csdn.net/catoop/article/details/50501706
 */
@Configuration
public class JxWebAppConfigurer  extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //相对路径的测试没有成功，classpath没有起到作用，暂时使用绝对路径吧
        registry.addResourceHandler("/myres/**").addResourceLocations("classpath:/resources/");
        // 可以直接使用addResourceLocations 指定磁盘绝对路径，同样可以配置多个位置，注意路径写法需要加上file:
        // registry.addResourceHandler("/myimgs/**").addResourceLocations("file:H:/myimgs/");
        // registry.addResourceHandler("/**").addResourceLocations("file:C:/Dev/uvlab-cloud/source/uvlab.site/site-springboot/src/main/webapp/");
//        registry.addResourceHandler("/**").addResourceLocations("file:E:\\uvlab\\site-springboot\\src\\main\\webapp\\");
        registry.addResourceHandler("/**").addResourceLocations("file:E:\\Code\\uvlab.site\\site-springboot\\src\\main\\webapp\\");

        // 访问myres根目录下的fengjing.jpg 的URL为 http://localhost:8080/fengjing.jpg （/** 会覆盖系统默认的配置）
        // registry.addResourceHandler("/**").addResourceLocations("classpath:/myres/").addResourceLocations("classpath:/static/");

        super.addResourceHandlers(registry);
    }
}